package 山峰和山谷;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    static int N = 1010, n;
    static boolean has_higher, has_lower;
    static int[][] h = new int[N][N];
    static boolean[][] st = new boolean[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                h[i][j] = in.nextInt();
            }
        }
        int res1 = 0, res2 = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (!st[i][j]) {
                    has_higher = false;
                    has_lower = false;
                    bfs(new PII(i, j));
                    if (!has_higher) {
                        res1++;
                    }
                    if (!has_lower) {
                        res2++;
                    }
                }
            }
        }
        System.out.println(res1 + " " + res2);
    }

    private static void bfs(PII start) {
        Queue<PII> q = new LinkedList<>();
        q.offer(start);
        st[start.x][start.y] = true;
        while (!q.isEmpty()) {
            PII t = q.poll();
            for (int i = t.x - 1; i <= t.x + 1; i++) {
                for (int j = t.y - 1; j <= t.y + 1; j++) {
                    if (i < 0 || i >= n || j < 0 || j >= n) {
                        continue;
                    }
                    if (h[i][j] != h[t.x][t.y]) {
                        if (h[t.x][t.y] > h[i][j]) {
                            has_lower = true;
                        } else if (h[t.x][t.y] < h[i][j]) {
                            has_higher = true;
                        }
                    } else if (!st[i][j]) {
                        q.offer(new PII(i, j));
                        st[i][j] = true;
                    }
                }
            }
        }
    }
}

class PII {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }
}